package com.socket.nio.nio.chat.example.handler;

import com.socket.nio.nio.chat.example.protocol.ChatMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @author Hexudong
 * @date 2025/5/12
 */
public class ChatClientHandler extends SimpleChannelInboundHandler<ChatMessage.Msg> {

  @Override
  protected void channelRead0(ChannelHandlerContext ctx, ChatMessage.Msg msg) {
    switch (msg.getType()) {
      case SYSTEM:
        System.out.println("[SYSTEM] " + msg.getContent());
        break;
      case TEXT:
        System.out.println("[Private from " + msg.getUsername() + "] " + msg.getContent());
        break;
      case GROUP_MSG:
        System.out.println("[Group " + msg.getGroupName() + " from " + msg.getUsername() + "] " + msg.getContent());
        break;
    }
  }
}
